package com.topscomm.mpm.script;

import com.topscomm.basic.exception.MessageException;
import com.topscomm.cbo.pojo.CboApprovalNodeInsEntity;
import com.topscomm.mpm.pojo.MpmProjectTeamEntity;
import com.topscomm.mpm.service.impl.MpmProjectTeamService;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.tap.ITapService;
import com.topscomm.tap.TapEntity;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author wudaliang
 * @date 2021/2/2
 * @description:
 * @modify:
 */
public class MpmProjectAppointCheckTeamScript {
    /**
     * @author: wudaliang
     * @date: 2021-02-01
     * @description: 提交审批任命书时，对项目组成员进行校验
     * @return:
     * @modify:
     */
    @Transactional
    public void checkTeam(ITapService service, TapEntity entity)throws Exception{
        //审批节点实例
        CboApprovalNodeInsEntity nodeins = (CboApprovalNodeInsEntity) entity;
        String sourceid = ConvertUtil.convertToString(nodeins.getSourceid());
        MpmProjectTeamService mpmProjectTeamService = (MpmProjectTeamService) SpringUtil.getBean("mpmProjectTeamService");
        StringBufferProxy sql = new StringBufferProxy();
        sql.appendSingle("appointmentid = '{0}'",sourceid);
        List<MpmProjectTeamEntity> mpmProjectTeamEntities = mpmProjectTeamService
            .queryByWhere(sql.toString());
        for (MpmProjectTeamEntity e:mpmProjectTeamEntities) {
            if(e.getDuty()==null){
                throw new MessageException("项目组成员的职责不能为空！");
            }
        }
    }

}
